BASS_ChannelSetSync

Sets up a synchronizer on a MOD music or file stream channel.

HSYNC WINAPI BASS_ChannelSetSync(
    DWORD handle,
    DWORD type,
    DWORD param,
    SYNCPROC *proc
);

Parameters
handleThe channel handle... a HMUSIC or HSTREAM.
typeThe type of sync... see the table below. If you want the sync to occur only once, then also use the BASS_SYNC_ONETIME flag.
paramThe sync parameters, depends on the sync type... see the table below.
procThe callback function.

Sync types, with param and SYNCPROC data definitions.
BASS_SYNC_MUSICPOSSync when a MOD music reaches a position.
param : LOWORD = order (0=first, -1=all), HIWORD = row (0=first, -1=all). data : LOWORD = order, HIWORD = row.
BASS_SYNC_MUSICINSTSync when an instrument (sample for the MOD/S3M/MTM formats) is played in a MOD music (not including retrigs).
param : LOWORD = instrument (1=first), HIWORD = note (0=c0...119=b9, -1=all). data : LOWORD = note, HIWORD = volume (0-64).
BASS_SYNC_ENDSync when a MOD music or file stream reaches the end. Note that some MOD musics never reach the end, they may jump to another position first.
param : not used. data : not used.

Return value
If succesful, then the new synchronizer's handle is returned, else 0 is returned. Use BASS_ErrorGetCode to get the error code.

Error codes
BASS_ERROR_HANDLEhandle is not a valid channel.
BASS_ERROR_ILLPARAMAn illegal param was specified.
BASS_ERROR_ILLTYPEAn illegal type was specified.

Remarks
Multiple synchronizers may be used per channel. Use BASS_ChannelRemoveSync to remove a synchronizer. If the BASS_SYNC_ONETIME flag is used, then the sync is automatically removed after it's occured (ie. there's no need to remove it manually).

The channel (ie. MOD music) does not have to be playing to set a synchronizer, you can set synchronizers before or while playing the music. Equally, you can also remove synchronizers at any time.

Example
To do some processing until a MOD music reaches the 10th order.

BOOL order10=FALSE; // the order 10 flag
...
// the sync callback
DWORD CALLBACK MySyncProc(HSYNC handle, DWORD channel, DWORD data) {
    order10=TRUE; // set the order 10 flag
}
...
BASS_ChannelSetSync(a_music, BASS_SYNC_MUSICPOS|BASS_SYNC_ONETIME, MAKELONG(10,0), &MySyncProc); // set the one-time order 10 sync
while (!order10) {
    // order 10 has not arrived, so do some processing
}
// order 10 has arrived!

See also
BASS_ChannelRemoveSync, SYNCPROC callback